package com.cyzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyzy.domain.dto.ResponseData;
import com.cyzy.domain.query.LogQuery;
import com.cyzy.domain.vo.TLog;
import com.cyzy.domain.vo.TPlantVo;
import com.cyzy.mapper.LogMapper;
import com.cyzy.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogImpl implements LogService {
    //    日志操作记录
    @Autowired
    private LogMapper logMapper;
    @Override
    public ResponseData logdata(LogQuery logQuery) {
        // 创建分页对象
        Page<TLog> page = new Page<>(logQuery.getCurrentPage(), logQuery.getSize());
        // 使用 QueryWrapper 构造查询条件
        QueryWrapper<TLog> queryWrapper = new QueryWrapper<>();
        if (logQuery.getUserId() != 0) {
            queryWrapper.eq("user_id", logQuery.getUserId());
        }
        if (logQuery.getOperation() != null) {
            queryWrapper.like("operation", logQuery.getOperation());
        }
        // 查询分页数据
        Page<TLog> plantPage = logMapper.selectPage(page, queryWrapper);
        // 获取分页数据列表
        List<TLog> data = plantPage.getRecords();

        // 将分页数据封装到 ResponseData 中
        ResponseData responseData = new ResponseData();
        responseData.setData(data);
        responseData.setCode(200);
        return responseData;
    }
}
